// import PIXI from 'pixi.js'
import 'pixi.js'
import BaseCell from '@/pixi-core/cell/base-cell'
import Cell1 from '@/pixi-core/cell/cell1'
import Cell2 from '@/pixi-core/cell/cell2'
import Cell3 from '@/pixi-core/cell/cell3'
import Vue from 'vue'
import LinesLayer from '@/pixi-core/layer/lines-layer'

export default function () {
  var app = new PIXI.Application()  
  app.stage.interactive = true

  // var linesLayer = new LinesLayer()
  // app.stage.addChild(linesLayer)
  // var bunny2 = new Cell1()
  // bunny2.x = 0
  // bunny2.y = 0
  // linesLayer.addChild(bunny2)

  var cellList = [1, 2, 3, 4]
  cellList.forEach((value, index) => {
    var bunny = new Cell1()
    bunny.index = app.stage.children.length
    bunny.x = 600 * Math.random()
    bunny.y = 600 * Math.random()
    app.stage.addChild(bunny)
  })
  
  app.ticker.add(function (delta) {
    
  })

  const handleAddCell = (type) => {
    var bunny
    switch (type) {
      case 1: bunny = new Cell1(); break;
      case 2: bunny = new Cell2(); break;
      case 3: bunny = new Cell3(); break;    
      default:
        break;
    }
    bunny.index = app.stage.children.length
    app.stage.addChild(bunny)
  }
  Vue.bus.on('addCell', handleAddCell)

  const handleAddCellLink = (cellFrom) => {
    app.stage.on('pointerup', (event) => {
      // console.log(event)
    })
    .on('pointermove', (event) => {
      // console.log('move')
    })
  }
  Vue.bus.on('addCellLink', handleAddCellLink)
  // Vue.bus.on('addCell2', handleAddCell)
  // Vue.bus.on('addCell3', handleAddCell)
  // console.log(Vue.bus)
  return app
}

